<template>
  <view class="my-search">
    <view class="search-l">
      <view class="l-sayhi">
        下午好
      </view>
      <view class="l-name">
        {{userInfo.nickName||'游客'}}
      </view>
    </view>
    <view class="search-r">
      <image src="../../static/svg/search.svg" mode=""></image>
      <input type="text" placeholder="输入商品名称" v-model="keyword" @input="inputHandler">
    </view>
  </view>
</template>

<script>
  import {
    mapState
  } from "vuex"
  export default {
    name: "MySearch",
    computed: {
      ...mapState("user", ["userInfo"])
    },
    data() {
      return {
        keyword: ""
      };
    },
    methods: {
      inputHandler() {
        clearTimeout(this.timer)
        this.timer = setTimeout(() => {
          uni.navigateTo({
            url: '/pages/search_res/search_res?keyword=' + this.keyword
          })
          this.keyword = ""
        }, 500)
      }
    }
  }
</script>

<style lang="scss" scoped>
  .my-search {
    position: fixed;
    z-index: 999;
    top: 0;
    left: 0;
    background-color: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20rpx;
    box-sizing: border-box;
    width: 100%;

    .search-l {
      display: flex;
      height: 100%;
      flex: 1;
      font-size: 20rpx;
      font-weight: bold;

      .l-sayhi {
        color: #75757a;
        width: 72rpx;
      }

      .l-name {
        color: #375fd4;
        margin-left: 20rpx;
        flex: 1;
      }
    }

    .search-r {
      height: 100%;
      flex: 2;
      padding-left: 10rpx;
      position: relative;

      image {
        height: 30rpx;
        width: 30rpx;
        position: absolute;
        top: 50%;
        transform: translate(0, -50%);
        left: 30rpx;
      }

      input {
        background-color: #f7f8fa;
        padding: 20rpx 0;
        font-size: 26rpx;
        border-radius: 50px;
        padding-left: 70rpx;
      }
    }
  }
</style>
